//
//  Car_CommentTableViewCell.m
//  CarUser
//
//  Created by ayi on 2019/1/10.
//  Copyright © 2019 王森林. All rights reserved.
//

#import "Car_CommentTableViewCell.h"

@interface Car_CommentTableViewCell()

@property (nonatomic, strong) UIImageView *logoImgv;//图片
@property (nonatomic, strong) UILabel *titleLab;//名称
@property (nonatomic, strong) UIView *contentBgView;//内容背景层
@property (nonatomic, strong) UILabel *commentLab;//内容
@property (nonatomic, strong) UILabel *timeLab;//时间

@property (nonatomic, strong) UIButton *commentBtn;//评论
@property (nonatomic, strong) UIButton *favorBtn;//点赞


@end

@implementation Car_CommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (Car_CommentTableViewCell *)initCellWithReuseIdentifier:(NSString *)reuseIdentifier andTab:(UITableView *)tab{
    Car_CommentTableViewCell *cell = [tab dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[Car_CommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _logoImgv = [[UIImageView alloc]init];
        _titleLab = [UILabel customInitLabWithFont:14 andTextColor:Common_TextColor andAlign:NSTextAlignmentLeft];
        _contentBgView = [[UIView alloc]init];
        _contentBgView.backgroundColor = Common_Head_Color;
        _contentBgView.layer.masksToBounds = YES;
        _contentBgView.layer.cornerRadius = 4;
        _commentLab = [UILabel customInitLabWithFont:12 andTextColor:Common_TextColor andAlign:NSTextAlignmentLeft];
        _commentLab.numberOfLines = 0;
        _timeLab = [UILabel customInitLabWithFont:10 andTextColor:Common_TextColor andAlign:NSTextAlignmentLeft];
//        UIView *lineview = [[UIView alloc]init];lineview.backgroundColor = Common_SepeColor;
        
        _commentBtn = ({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setImage:IMG(@"pinglun") forState:UIControlStateNormal];
            btn.titleLabel.font = FONT_SIZE(10);
            [btn setTitleColor:Common_TextColor forState:UIControlStateNormal];
            btn;
        });
        _favorBtn = ({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setImage:IMG(@"zan1") forState:UIControlStateNormal];
            btn.titleLabel.font = FONT_SIZE(10);
            [btn setTitleColor:Common_TextColor forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(commonentBtnAction:) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
        
        [self.contentView addSubview:_logoImgv];
        [self.contentView addSubview:_titleLab];
        [self.contentView addSubview:_contentBgView];
        [_contentBgView addSubview:_commentLab];
        [self.contentView addSubview:_timeLab];
//        [self.contentView addSubview:lineview];
        
        [self.contentView addSubview:_commentBtn];
        [self.contentView addSubview:_favorBtn];
        
        [_logoImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.left.mas_equalTo(15);
            make.height.mas_equalTo(35);
            make.width.mas_equalTo(35);
        }];
        _logoImgv.layer.masksToBounds = YES;
        _logoImgv.layer.cornerRadius = 35/2;
        
        [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.logoImgv.mas_centerY);
            make.left.mas_equalTo(self.logoImgv.mas_right).offset(8);
            make.right.mas_equalTo(-15);
            make.height.mas_equalTo(ceilf(self.titleLab.font.lineHeight));
        }];
        
        [_contentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLab.mas_bottom).offset(15);
            make.left.equalTo(self.titleLab.mas_left);
            make.right.mas_equalTo(-15);
//            make.height.mas_lessThanOrEqualTo(20);
        }];
        
        [_commentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(10, 8, 8, 10));
        }];
        [_commentLab setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        
        [_favorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentBgView.mas_bottom).offset(4);
            make.right.mas_equalTo(-15);
            make.height.mas_equalTo(38);
            make.bottom.mas_equalTo(-8);
        }];
        
        [_commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.favorBtn.mas_centerY);
            make.right.equalTo(self.favorBtn.mas_right).offset(-10);
            make.height.mas_equalTo(38);
        }];
        
        [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.favorBtn.mas_centerY);
            make.left.equalTo(self.titleLab.mas_left);
            make.right.equalTo(self.commentBtn.mas_left).offset(-10);
        }];
        
//        [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(15);
//            make.right.mas_equalTo(-15);
//            (void)make.bottom;
//            make.height.mas_equalTo(.5f);
//        }];
        
      
        
    }
    return self;
}

- (void)setModel:(CarCommentModel *)model{
    _model = model;
    
    @weakify(self);
    [self.logoImgv sd_setImageWithURL:[NSURL URLWithString:model.PHOTO1] placeholderImage:[UIImage getDefaultPersonLogoImage] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        @strongify(self);
        if (image && cacheType == SDImageCacheTypeNone) {
            [self.logoImgv.layer addCustomImageViewLayerAnimation];
        }
    }];
    
    self.titleLab.text = model.NICK00 ? : model.PLZH00;
    self.commentLab.text = model.PLNR00 ? : @" ";
    self.timeLab.text = model.SJ0000;
    [self.favorBtn setTitle:model.DZS000 forState:UIControlStateNormal];
    if (model.DZFLAG.integerValue == 1) {
      [self.favorBtn setImage:IMG(@"zan2") forState:UIControlStateNormal];
    } else {
        
        [self.favorBtn setImage:IMG(@"zan1") forState:UIControlStateNormal];
    }
    
    self.commentBtn.hidden = YES;
}

- (void)commonentBtnAction:(UIButton *)btn{
    if (self.commentZanBtnCallBck) {
        self.commentZanBtnCallBck(self.model);
    }
}



@end











@interface Car_CommentDefalutTableViewCell()

@property (nonatomic, strong) UIImageView *logoImgv;
@property (nonatomic, strong) UILabel *contentLab;

@end

@implementation Car_CommentDefalutTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+ (Car_CommentDefalutTableViewCell *)initCellWithReuseIdentifier:(NSString *)reuseIdentifier andTab:(UITableView *)tab{
    Car_CommentDefalutTableViewCell *cell = [tab dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[Car_CommentDefalutTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _logoImgv = [[UIImageView alloc]init];
        _contentLab = [UILabel customInitLabWithFont:14 andTextColor:Common_TextLowColor andAlign:NSTextAlignmentCenter];
        _contentLab.numberOfLines = 0;
        
        [self.contentView addSubview:_logoImgv];
        [self.contentView addSubview:_contentLab];
        
        [_logoImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(4);
            (void)make.centerX;
        }];
        
        [_contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.logoImgv.mas_bottom).offset(4);
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.bottom.mas_equalTo(-10);
        }];
        
        
        _logoImgv.image = IMG(@"pinglun");
        _contentLab.text = @"话题还没有回复哦～\n快来抢沙发吧";
    }
    return self;
}


@end
